#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int N = 1e5+5;
const int L = 1e6+6;
const ld eps = 1e-10;

int n,m,len,p[N],h[L];
ld V;

struct node {
    int v,a;
    int d,l,r;
    void init(){
        cin>>d>>v>>a;
        l=r=-1;
        if (a==0){
            if (v>V) l=d,r=len; 
        }
        else if (a>0){
            if (v>V) l=d,r=len;
            else{
                ld lb=(V*V-v*v)/(2.*a);
                l=lb;
                while (1.*l<=(V*V-v*v)/(2.*a)) l++;
                l+=d;
                if (l>len) l=r=-1;
                else r=len;
            }
        }
        else{
            if (v>=V){
                l=d;
                ld rb=(V*V-v*v)/(2.*a);
                r=rb;
                while (1.*r>=(V*V-v*v)/(2.*a)) r--;
                r+=d;
                r=min(r,len);
            }
        }
       // cout<<l<<","<<r<<"\n";
    }
} a[N];

bool cmp(pair<int,int> u,pair<int,int> v){
    return u.second!=v.second?u.second<v.second:u.first<v.first;
}

void solve(){
    cin>>n>>m>>len>>V;
    for (int i=1; i<=n; i++){
        a[i].init();
    }
    for (int i=1; i<=m; i++){
        cin>>p[i];
        h[p[i]]++;
    }
    for (int i=1; i<=len; i++){
        h[i]+=h[i-1];
    }
    vector<pair<int,int> > v;
    for (int i=1; i<=n; i++){
        if (a[i].l==-1 || a[i].r==-1) continue;
        if (h[a[i].r]-(a[i].l?h[a[i].l-1]:0)>0){
            v.push_back({a[i].l,a[i].r});
        }
    }
    cout<<v.size()<<" ";
    sort(v.begin(),v.end(),cmp);
    int cur=0,cnt=0;
    for (auto u : v){
     //   cout<<u.first<<"~"<<u.second<<"\n";
        if (p[cur]>=u.first) continue;
        while (cur<m && p[cur+1]<=u.second) cur++;
        cnt++;
    }
    cout<<m-cnt<<"\n";
    for (int i=1; i<=len; i++) h[i]=0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while (t--){
        solve();
    }
    return 0;
}

/*
Things to check:
    - int/long long overflow?
    - mod, +mod, %mod?
    - array bounds?
    - Places where you think can't be wrong.
    - Functions should return if not "void".
    - what is the memory limit? the mod? the name etc.
Things to think of:
    - Be brave to guess and be optimistic.
    - Start from a trivial case.
    - What is the expected time to finish this problem?
Do not be afraid of a problem, try.
Do not devote all your time into a problem, look at other problems.
*/